• Jump To … +
    main.js separate.js single.js web-apg-api.js main.js web-conv-api.js ast.js csv.js dangling-else.js display.js flags.js float.js limits.js main.js multiline-mode.js recursive.js replace.js rules.js split.js testonly.js trace.js udt.js unicode.js web-email.js word-boundaries.js main.js phone-number.js web-main.js web-phone-number.js main.js phone-number.js setup.js translate.js xml.js branch-fail-grammar.js main.js parent-mode-grammar.js setup.js universal-mode-grammar.js colors-app.js colors-callbacks.js colors.js main.js more-app.js more-setup.js more.js ast-callbacks.js bad-input.js basic.js ini-file.js main.js parser-callbacks.js setup.js trace.js anbncn.js and.js c-comment.js compound.js main.js nested.js not.js setup.js boundaries-grammar.js boundaries.js comment-grammar.js comment.js main.js negative-grammar.js negative.js positive-grammar.js positive.js setup.js main.js odata-grammar.js run.js setup.js area-code.js lookaround.js main.js phone-number.js setup.js simple.js all-operators.js default.js fancy-number.js limited-lines.js main.js select-operators.js select-rules.js setup.js main.js minimal.js parent-u.js parent.js phone-number.js setup.js stats.js trace.js universal-u.js universal.js callbacks.js grammar.js main.js parser.js writeHtml.js LICENSE.md README.md index.md
  • main.js

  • §
    /*  *************************************************************************************
     *   copyright: Copyright (c) 2025 Lowell D. Thomas, all rights reserved
     *     license: BSD-2-Clause (https://opensource.org/licenses/BSD-2-Clause)
     *   ********************************************************************************* */
  • §

    This is the driver for the URI example.

    module.exports = function main(args) {
      /* display the program arguments */
      console.log('uri args');
      console.dir(args);
      /* the example description */
      const desc = [
        '',
        'Description: The URI example features a complete and well-tested URI (RFC 3986) parser.',
        'With this test any URI can be parsed into its components:',
        '  scheme',
        '  userinfo',
        '  host',
        '  port',
        '  path',
        '  query',
        '  fragment',
      ].join('\n');
    
      /* the help screen */
      const example = 'http://user@example.com:123/abs/path?q1=a1#body';
      const help = [
        '',
        'Usage: npm run uri [-- arg]',
        '  arg: <none>    (no arg) displays example description and help screen.',
        '       --help    display help screen.',
        '       -h        display help screen.',
        '       URI       the URI string to parse, e.g. http://user@example.com:123/path?query#fragment',
        '       all       to verify that all is well, parses the specific URI:',
        `                 ${example}`,
      ].join('\n');
      if (!args[0]) {
  • §

    If no args, display the description and the help screen.

        console.log(desc);
        console.log(help);
      } else if (args[0] === '--help' || args[0] === '-h') {
  • §

    If --help or -h, display the help screen only.

        console.log(help);
      } else if (args[0] === 'all') {
  • §

    If all, parse a fixed example. Note: the all option is used by the script src/all.sh. It runs all the examples in the src directory as a sort of unit test. This is a bit of a hack, but it works.

        console.log(`Parsing example URI: ${example}`);
        console.dir(require('./parser')(example));
      } else {
  • §

    Otherwise, parse the URI passed as an argument.

        console.dir(require('./parser')(args[0]));
      }
    };